(function ($app) {
    $app.module('gtPartyApp').controller('assesTemplateDetailCtrl', function ($scope, $http, $modal, $ocLazyLoad, $alert, $loading, $state, $partySelect, $stateParams, AuthUser, $filter, $bsRouterState) {
        $stateParams = $bsRouterState.$params($scope);

        //定义数据集合
        $scope.dataModel = {
            id: $stateParams.id == undefined ? "" : $stateParams.id
        };
        $scope.sumScore = 0;

        //获取数据
        $scope.getById = function () {
            $http.get("../../api/jcdzzpb/assestemplate/get", {
                params: {
                    'id': $scope.dataModel.id
                }
            }).then(function (result) {
                if (!result.data.success) {
                    $scope.showMsg('错误', result.data.extdata.message);
                    return false;
                }

                $scope.dataModel = result.data.item;
                $scope.getSumItemScore();
            }, function () {
                $scope.showMsg('错误', '服务器错误');
            });
        };

        $scope.getSumItemScore = function (){
            $scope.sumScore = 0;
            $scope.dataModel.itemList.forEach(x=>{
                $scope.sumScore += x.itemScore;
            })
        }

        $scope.pagechange = function () {
            var inTab = $bsRouterState.$getRouteType() == 'tab';
            if (inTab) {
                $bsRouterState.$closeTab($scope);
            } else {
                window.history.back();
            }
        };

        $scope.getById();

    });
})(angular);